#include <QCoreApplication>
#include <iostream>
#include <QList>
int removeDuplicates(QList<int>);
int main(int argc, char *argv[])
{
    using namespace std;
    QCoreApplication a(argc, argv);
    QList<int> list;
    int length = 0;
    cout << "Number of list's element: " << endl;
    int number;
    cin >> number;
    for (int i = 0; i < number; i++) {
        int temp;
        cin >> temp;
        list.append(temp);
    }
    length = removeDuplicates(list);
    cout << "Number after removing duplicates: " <<length;
    return a.exec();
}

int removeDuplicates(QList<int> list)
{
    //检测到两个相邻元素相同时，利用removeOne函数删除其中一个元素，指针不改变位置；
    //相邻两个元素不相同时，指针前进一位。
    for (int i = 1; i < list.size(); i++) {
        if (list[i] == list[i-1]) {
            list.removeOne(list[i]);
            i--;
        }
    }
    return list.size();     //返回数组长度
}
